<?php

class CF_FieldSpec {

// ----------------------------- Field Spec settings are as below:	
//$field_spec['<column>'] ['show'] = {'0' = notshown, '1' = show readonly, 'L' = show, use list (manual join), E = editable;
//$field_spec['<column>'] ['key'] = {1 = key field, 0 of not (or dont include)};
//$field_spec['<column>'] ['select'] = {'T' = text, 'D' = dropdown select, 'C' = checkbox (for 1 or 0 boolean), 'R' = radiogroup, 'A' = textarea, 'DT' = calendar for date-time};
//$field_spec['<column>'] ['filter'] = {1 if value is filtered for, 0 or undefined if not};	
//$field_spec['<column>'] ['filter'] [<filterparam>] ['op']  = {=,<,>,LIKE}
//$field_spec['<column>'] ['filter'] [<filterparam>] ['filterhead'>] = filter heading 
//$field_spec['<column>'] ['filter'] [<filterparam>] ['source'>] = source table or alias for column in filter (optional)
//$field_spec['<column>'] ['add'] = {1 = include value as input in add box, 0 or undefined = do not };
//$field_spec['<column>'] ['size'] = size of input field, or columns (cols) for textarea;
//$field_spec['<column>'] ['rows'] = rows of textarea or listbox (future);
//$field_spec['<column>'] ['headname'] = {Name to show on column heading or input heading};
//$field_spec['<column>'] ['keyvalue'] = {array column to use for key in drop-down lists} ;
//For lists, Not needed if columns 'keyvalue' and 'showvalue' are used in array, no need to define these specs;
//$field_spec['<column>'] ['showvalue'] = {array column to use for shown value in drop-down lists};
//$field_spec['<column>'] ['rawformat']	= additional html to include inside the input field;
//$field_spec['<column>'] ['image']	= image file name of image to associate with control (implemetned for calendar);
//$field_spec['<column>'] ['showdateformat'] = format string for inital display of shown date, using php date formatters;
//$field_spec['<column>'] ['cal'] ['ifFormat'] = format string of date from database (or whatever) for input to calendar, js date formatters;
//$field_spec['<column>'] ['cal'] ['align'] = {'T1' Shows calendar above imput control (default), 'B1' shows it below controls};
//$field_spec['<column>'] ['cal'] ['showsTime'] = {true = show time in calendar below date, false (Default) = show and use calendar for dates only};
//$field_spec['<column>'] ['cal'] ['singleClick'] = {true = (Default) open calendar with single click, false = double click for calendar};
//$field_spec['<column>'] ['allowhtml'] = {true:  do not escape html (to allow images, etc), false (or unset by default) escapes using htmlspecialchars)};
//$field_spec['<column>'] ['source'] = table name for source table, will be appended to filters to resolve ambiguies with multiple tables
//$field_spec['<column>'] ['makefunction'] = construct function - function to call to create the field from the data (defaults to the col_name, make_colname)
//$field_spec['<column>'] ['list'] = static lookup list for column
//$field_spec['<column>'] ['listquery'] = query for lookup list , end in WHERE 1
//$field_spec['<column>'] ['listqueryorder'] = array ['column'=>{'ASC','DESC'}
//$field_spec['<column>'] ['listqueryparams'] = array ['<param1>','<param2>'...]

var $field_spec;
// construct :  jsut bind (by reference) to a fieldspec.
function __construct(&$field_spec){

	$this->field_spec = $field_spec;
}

//return $keyvaluelist array

// return $newvaluelist array (editable, or all)

// set LookupResolver from FieldSpec
function SetupLookupResolver(&$LR){
	if(is_array($this->field_spec)){
	foreach($this->field_spec as $column=>$col_spec){
		if(is_array($col_spec['list'])){
			$LR->static_spec[$column] = $col_spec['list'];
		}
		if(isset($col_spec['listquery'])){
			$LR->query_spec[$column] = array('query'=>$col_spec['listquery'], 'params'=>$col_spec['listqueryparams'], 'orderby'=>$col_spec['listqueryorder']);
		}

	}
	}
		//print_r($LR);
}


// Return a simplified array by column name array[column] = [$settting] for a specific
// setting within the fieldspec.
function GetColumnsArray($setting = null){
	$columns = array();
	if(is_array($this->field_spec)){	
	foreach($this->field_spec AS $column=>$col_spec){
		if(!is_null($setting)){
			if(!empty($col_spec[$setting])){
				$columns[] = $column;
			}
		}else{
			$columns[] = $column;
		}
	}
	}
	return $columns;
}

}


?>